//
//  CANetParams.m
//  Test
//
//  Created by xgc on 12/25/17.
//  Copyright © 2017 xgc. All rights reserved.
//

#import "CANetParams.h"


@implementation CANetParams

+(id)initWithNetParams: (NetParams*)params{
    
    CANetParams* netParams = [[CANetParams alloc]init];
    netParams.csymbol = [NSString stringWithCString:params->getSymbol().c_str() encoding:[NSString defaultCStringEncoding]];
    netParams.coinType = params->getCoinType();
    netParams.netType = params->getNetType();
    netParams.version = params->getVersion();
    KeyPath path = params->getKeyPath();
    netParams.keyPath = [CAKeyPath initWithKeyPath:&path];
    netParams.HDprivate = params->getHDprivate();
    netParams.HDpublic = params->getHDpublic();
    netParams.P2KH = params->getP2KH();
    netParams.P2SH = params->getP2SH();
    netParams.keyprefixes = params->getKeyprefixes();
    netParams.ApiVersion = params->getApiVersion();
    netParams.N = params->getN();
    netParams.R = params->getR();
    netParams.P = params->getP();
    
    return netParams;
    
}

-(NetParams*) toNetParams
{
    NetParams* netParams = new NetParams();
    KeyPath* keyPath = [self.keyPath toKeyPath];
    netParams->setKeyPath(*keyPath);
    delete keyPath;
    
    netParams->setSymbol([self.csymbol UTF8String]);
    netParams->setVersion(self.version);
    netParams->setNetType((NetworkType)self.netType);
    netParams->setCoinType((CoinType)self.coinType);
    netParams->setHDprivate((uint32_t)self.HDprivate);
    netParams->setHDpublic((uint32_t) self.HDpublic);
    netParams->setP2KH((uint32_t)self.P2KH);
    netParams->setP2SH((uint32_t)self.P2SH);
    netParams->setKeyprefixes((uint8_t)self.keyprefixes);
    netParams->setApiVersion((uint16_t)self.ApiVersion);
    netParams->setN((uint32_t)self.N);
    netParams->setR((uint32_t)self.R);
    netParams->setP((uint32_t)self.P);
    
    return netParams;
}

-(id)init {
    if (self = [super init]) {
        self.ApiVersion = 0x01;
        self.version = 0x02;
        self.N = 32768;
        self.R = 8;
        self.P = 1;
    }
    return self;
}

@end
